package com.bwie.bargain.controller;


import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;
import com.bwie.bargain.entity.BargainEntity;
import com.bwie.bargain.service.BargainService;
import com.bwie.common.utils.PageUtils;
import com.bwie.common.utils.R;


/**
 *
 *
 * @author gy
 * @email gy@gmail.com
 * @date 2022-07-05 09:11:06
 */
@RestController
@RequestMapping("bargain/bargain")
public class BargainController {
    @Autowired
    private BargainService bargainService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = bargainService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{bargainId}")
    public R info(@PathVariable("bargainId") Integer bargainId){
		BargainEntity bargain = bargainService.getById(bargainId);

        return R.ok().put("bargain", bargain);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody BargainEntity bargain){
		bargainService.save(bargain);

        return R.ok();
    }

//    /**
//     * 修改
//     */
//    @RequestMapping("/update")
//    public R update(@RequestBody BargainEntity bargain){
//		bargainService.updateById(bargain);
//
//        return R.ok();
//    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] bargainIds){
		bargainService.removeByIds(Arrays.asList(bargainIds));

        return R.ok();
    }


    @RequestMapping("/lists")
    public List lists(@RequestBody BargainEntity bargainEntity){
      List<BargainEntity> lists = bargainService.lists();
      return lists;
    }


    @RequestMapping("/updates")
    public R updates(@RequestBody BargainEntity bargain){
        bargainService.updateById(bargain);

        return R.ok();
    }

}
